package benny_driving_ser.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import java.sql.Statement;

import benny_driving_ser.util.DBUtil;

public class CheckPWDVersionImpl {
	private CheckPWDVersionImpl() {
	}

	private static class CheckPWDVersionImplHolder {
		private static CheckPWDVersionImpl instance = new CheckPWDVersionImpl();
	}

	public static CheckPWDVersionImpl getInstance() {
		return CheckPWDVersionImplHolder.instance;
	}

	public boolean verifyPWDVersion(String driId, String pwdVersion) {
		String queryPWDVersion = "SELECT pwd_version FROM t_user WHERE id = "
				+ driId;
		Connection con = DBUtil.getInstance().openConnection();
		try {
			Statement s = con.createStatement();
			ResultSet rs = s.executeQuery(queryPWDVersion);
			if (rs.next()) {
				if (pwdVersion.equals(rs.getString(1))) {
					return true;
				}
				return false;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.getInstance().closeConnection(con);
		}
		return false;
	}
}
